package com.tanhua.backstage.service;

import cn.hutool.core.collection.CollUtil;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.backstage.vo.AddUsersVo;
import com.tanhua.backstage.vo.DataVo;
import com.tanhua.backstage.vo.DistributionVo;
import com.tanhua.backstage.vo.SummaryVo;
import com.tanhua.common.enums.AreaEnum;
import com.tanhua.common.enums.SexEnum;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.mapper.UserMapper;
import com.tanhua.common.pojo.User;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.dubbo.server.api.DashboardApi;
import com.tanhua.dubbo.server.pojo.UserLogin;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Slf4j
public class DashboardService {

    @Reference(version = "1.0.0")
    private DashboardApi dashboardApi;


    @Autowired
    private UserInfoMapper userInfoMapper;


    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserService userService;


    /**
     * 注册用户分布，行业top、年龄、性别、地区
     *
     * @param startDate 起始时间
     * @param endDate   结束时间
     * @return
     */

    public DistributionVo distribution(Long startDate, Long endDate) {

        if (ObjectUtil.equal(startDate, endDate)) {
            //如果前端给的起始时间和截止时间相同,说明是第一次登录,要给出时间的默认值(7天前到现在)
            Date now = new Date();
            endDate = now.getTime();//当前时间

            startDate = DateUtils.addDays(now, -7).getTime();//7天前

        }


        //根据起始时间查询出指定时间内不重复的userId
        List<UserLogin> userIdList = this.dashboardApi.queryUserIdByTime(startDate, endDate);

        if (ObjectUtil.isEmpty(userIdList)) {
            return null;
        }

        //根据userId查询mysql中的userInfo表
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id", userIdList);
        List<UserInfo> userInfoList = null;

        try {
            //查出userInfo集合
            userInfoList = this.userInfoMapper.selectList(queryWrapper);
        } catch (Exception e) {
            log.error("根据用户id查询userInfo集合出错..." + e);
        }

        List<DataVo> industryList = new ArrayList<>();    //行业分布
        List<DataVo> ageList = new ArrayList<>();    //年龄分布
        List<DataVo> genderList = new ArrayList<>();    //性别分布
        List<DataVo> localList = new ArrayList<>();    //地区分布
        List<DataVo> localTotalList = new ArrayList<>();    //地区合计


        //遍历UserInfo集合,封装行业分布集合对象industryList


        Map<String, Integer> ageMap = new HashMap<>();

        Map<String, Integer> industryMap = new HashMap<>();

        Map<String, Integer> genderMap = new HashMap<>();


        Map<String, Integer> localMap = new HashMap<>();


        Map<String, Integer> localTotalMap = new HashMap<>();


        /**
         * 封装industryList集合
         */


        //map集合，以字符串做键，以出现的数量为值

        for (UserInfo userInfo : userInfoList) {

            String industry = userInfo.getIndustry();

            //给map赋值,行业为键(无重复),出现的次数为值
            industryMap.put(industry, industryMap.containsKey(industry) ? industryMap.get(industry) + 1 : 1);

        }
        //遍历map集合,封装到industryList集合中
        fillListVo(industryMap, industryList);


        /**
         * 封装ageList集合
         */
        for (UserInfo userInfo : userInfoList) {


            String age = null;
            Integer ageValue = userInfo.getAge();

            if (ageValue >= 0 && ageValue <= 17) {
                age = "0-17岁";
            } else if (ageValue >= 18 && ageValue <= 23) {
                age = "18-23岁";
            } else if (ageValue >= 24 && ageValue <= 30) {
                age = "24-30岁";
            } else if (ageValue >= 31 && ageValue <= 40) {
                age = "31-40岁";
            } else if (ageValue >= 41 && ageValue <= 50) {
                age = "41-50岁";
            } else {
                age = "50岁+";
            }


            //给map赋值,age为键(无重复),出现的次数为值
            ageMap.put(age, industryMap.containsKey(age) ? ageMap.get(age) + 1 : 1);

        }
        //遍历map集合,封装到ageList集合中
        this.fillListVo(ageMap, ageList);


        /**
         * 封装genderList集合
         */
        for (UserInfo userInfo : userInfoList) {


            String gender = null;

            //获取用户性别
            SexEnum sex = userInfo.getSex();

            if (ObjectUtil.equal(sex, SexEnum.MAN)) {
                gender = "男性用户";
            } else {
                gender = "女性用户";
            }

            //给map赋值,性别为键(无重复),出现的次数为值
            genderMap.put(gender, industryMap.containsKey(gender) ? genderMap.get(gender) + 1 : 1);


        }
        //遍历map集合,封装到genderMap集合中
        this.fillListVo(genderMap, genderList);


        /**
         * 封装地区分布集合
         */
        for (UserInfo userInfo : userInfoList) {

            String local = userInfo.getCity();

            //给map赋值,地区为键(无重复),出现的次数为值
            localMap.put(local, localMap.containsKey(local) ? localMap.get(local) + 1 : 1);

        }
        //遍历map集合,封装到localMap集合中
        fillListVo(localMap, localList);


        /**
         * 封装地区合计集合
         */
        for (UserInfo userInfo : userInfoList) {

            String city = userInfo.getCity();
            String area = AreaEnum.getAreaByProvince(city);

            //给map赋值,行业为键(无重复),出现的次数为值
            localTotalMap.put(area, localTotalMap.containsKey(area) ? localTotalMap.get(area) + 1 : 1);
        }

        //遍历map集合,封装到localTotalMap集合中
        fillListVo(localTotalMap, localTotalList);


        //先构建一个Vo对象
        DistributionVo distributionVo = new DistributionVo();


        //封装distributionVo
        distributionVo.setIndustryDistribution(industryList);
        distributionVo.setAgeDistribution(ageList);
        distributionVo.setGenderDistribution(genderList);
        distributionVo.setLocalDistribution(localList);
        distributionVo.setLocalTotal(localTotalList);

        //把封装好的distributionVo对象返回前端
        return distributionVo;
    }


    //封装的方法
    private void fillListVo(Map<String, Integer> map, List<DataVo> list) {

        //获取所有键的集合。用keySet()方法实现
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            Integer count = map.get(key);
            DataVo dataVo = new DataVo();
            dataVo.setTitle(key);   //key是每一个行业的名称
            dataVo.setAmount(count);   //行业出现的次数

            list.add(dataVo);
        }
    }


    /**
     * 新增、活跃用户、次日留存率
     *
     * @param startDate 起始时间
     * @param endDate   结束时间
     * @param type      101 新增 102 活跃用户 103 次日留存率
     * @return
     */
    public AddUsersVo AddUserData(Long startDate, Long endDate, Integer type) {

/*
        if (ObjectUtil.equal(startDate, endDate)) {
            //如果前端给的起始时间和截止时间相同,说明是第一次登录,要给出时间的默认值(7天前到现在)
            Date now = new Date();
            endDate = now.getTime();//当前时间
            startDate = DateUtils.addDays(now, -7).getTime();//7天前

        }*/


        AddUsersVo addUsersVo = null;

        //匹配前端传来的类型   101 新增 102 活跃用户 103 次日留存率

        switch (type) {
            case 101:
                addUsersVo = this.queryAddUserByTime(startDate, endDate);
                break;
            case 102:
                addUsersVo = this.queryActiveUserByTime(startDate, endDate);
                break;
            case 103:
                addUsersVo = this.queryRetentionUserByTime(startDate, endDate);
                break;
        }

        return addUsersVo;
    }


    //获取指定日期的年份
    public Integer getYear(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.YEAR);
    }

    //获取指定日期的月份
    public Integer getMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return (cal.get(Calendar.MONTH)) + 1; //获取月份
    }

    //获取指定日期的day
    public Integer getDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.DATE);
    }

    //查询指定时间的次日留存率
    private AddUsersVo queryRetentionUserByTime(Long startDateTime, Long endDateTime) {
        //今年数据的集合
        List<DataVo> thisYearList = new ArrayList<>();

        //去年数据的集合
        List<DataVo> lastYearList = new ArrayList<>();


        //获取今年的今天的时间
        //获取开始时间的年月日
        Integer year = getYear(new Date(startDateTime));
        int startMonth = getMonth(new Date(startDateTime));
        int day = getDay(new Date(startDateTime));  //获取今天的日期

        //利用糊涂工具,算出两个起始和截止日期相隔的天数
        long totalDay = DateUtil.between(new Date(startDateTime), new Date(endDateTime), DateUnit.DAY, false);

        for (int i = 0; i <= totalDay; i++) {

            String startStr = year + "-" + startMonth + "-" + day + " 00:00:00";

            //今年指定天数的开始时间和结束时间
            long startTime = DateUtil.parseDateTime(startStr).getTime();

            //今年今日起始时间
            Date startDate = DateUtils.addDays(new Date(startTime), i);

            //今年今日结束时间
            Date endTime = DateUtils.addDays(startDate, 1);

            //今年今日的前一天的起始时间
            Date yesterdayStartTime = DateUtils.addDays(startDate, -1);

            //今年今日的前一天的新增用户集合
            List<User> userList = this.userService.queryUserListByTime(yesterdayStartTime, startDate);

            //分离出新增的用户id集合
            List<Object> userIdList = CollUtil.getFieldValues(userList, "id");

            //查询出今年的次日留存数量
            Integer thisYearCount = this.dashboardApi.queryActiveUserById(startDate.getTime(), endTime.getTime(), userIdList);

            String now = DateUtil.now();


            //去年今日的前一天的开始时间
            Date lastYearStartTime = DateUtils.addYears(yesterdayStartTime, -1);
            Date lastYearEndTime = DateUtils.addYears(startDate, -1);

            //获取到去年今日的前一天的新增用户集合
            List<User> userList1 = this.userService.queryUserListByTime(lastYearStartTime, lastYearEndTime);
            //分离出新增的用户id集合
            List<Object> userIdList1 = CollUtil.getFieldValues(userList1, "id");


            //先获取去年今日的起始时间
            Date lastYearStart = DateUtils.addYears(startDate, -1);
            Date lastYearEnd = DateUtils.addYears(endTime, -1);

            Integer lastYearCount = this.dashboardApi.queryActiveUserById(lastYearStart.getTime(), lastYearEnd.getTime(), userIdList1);


            //把今年数据封装到DataVo
            DataVo thisYearDataVo = this.getDataVo(thisYearCount, getMonth(startDate), getDay(startDate));
            DataVo lastYearDataVo = this.getDataVo(lastYearCount, getMonth(lastYearStartTime), getDay(lastYearStartTime));

            //把DataVo添加到对应集合中
            thisYearList.add(thisYearDataVo);
            lastYearList.add(lastYearDataVo);


        }

        //创建AddUsersVo对象,最后要返回给前端
        AddUsersVo addUsersVo = new AddUsersVo();
        addUsersVo.setThisYear(thisYearList);
        addUsersVo.setLastYear(lastYearList);

        return addUsersVo;

    }

    //查询指定时间的活跃用户数
    private AddUsersVo queryActiveUserByTime(Long startDateTime, Long endDateTime) {
        //今年数据的集合
        List<DataVo> thisYearList = new ArrayList<>();

        //去年数据的集合
        List<DataVo> lastYearList = new ArrayList<>();


        //获取今年的今天的时间
        //获取开始时间的年月日
        Integer year = getYear(new Date(startDateTime));
        int startMonth = getMonth(new Date(startDateTime));
        int day = getDay(new Date(startDateTime));  //获取今天的日期

        //利用糊涂工具,算出两个起始和截止日期相隔的天数
        long totalDay = DateUtil.between(new Date(startDateTime), new Date(endDateTime), DateUnit.DAY, false);

        for (int i = 0; i <= totalDay; i++) {

            String startStr = year + "-" + startMonth + "-" + day + " 00:00:00";

            //今年指定天数的开始时间和结束时间
            long startTime = DateUtil.parseDateTime(startStr).getTime();

            Date startDate = DateUtils.addDays(new Date(startTime), i);

            Date endTime = DateUtils.addDays(startDate, 1);

            //去年指定天数的开始时间和结束时间
            Date lastYearStartTime = DateUtils.addYears(new Date(startTime), -1);
            Date lastYearEndTime = DateUtils.addDays(lastYearStartTime, 1);

            //查询MongoDB
            //今年
            Integer thisYearCount = this.dashboardApi.queryActiveUser(startDate.getTime(), endTime.getTime());

            //去年
            Integer lastYearCount = this.dashboardApi.queryActiveUser(lastYearStartTime.getTime(), lastYearEndTime.getTime());

            //把今年数据封装到DataVo
            DataVo thisYearDataVo = this.getDataVo(thisYearCount, getMonth(startDate), getDay(startDate));
            DataVo lastYearDataVo = this.getDataVo(lastYearCount, getMonth(lastYearStartTime), getDay(lastYearStartTime));

            //把DataVo添加到对应集合中
            thisYearList.add(thisYearDataVo);
            lastYearList.add(lastYearDataVo);


        }

        //创建AddUsersVo对象,最后要返回给前端
        AddUsersVo addUsersVo = new AddUsersVo();
        addUsersVo.setThisYear(thisYearList);
        addUsersVo.setLastYear(lastYearList);

        return addUsersVo;

    }


    //查询指定时间的新增用户数
    private AddUsersVo queryAddUserByTime(Long startDateTime, Long endDateTime) {

        //今年数据的集合
        List<DataVo> thisYearList = new ArrayList<>();

        //去年数据的集合
        List<DataVo> lastYearList = new ArrayList<>();


        //获取今年的今天的时间
        //获取开始时间的年月日
        Integer year = getYear(new Date(startDateTime));
        int startMonth = getMonth(new Date(startDateTime));
        int day = getDay(new Date(startDateTime));  //获取今天的日期

        //利用糊涂工具,算出两个起始和截止日期相隔的天数
        long totalDay = DateUtil.between(new Date(startDateTime), new Date(endDateTime), DateUnit.DAY, false);

        for (int i = 0; i <= totalDay; i++) {

            String startStr = year + "-" + startMonth + "-" + day + " 00:00:00";

            //今年指定天数的开始时间和结束时间
            long startTime = DateUtil.parseDateTime(startStr).getTime();

            Date startDate = DateUtils.addDays(new Date(startTime), i);

            Date endTime = DateUtils.addDays(startDate, 1);

            //去年指定天数的开始时间和结束时间
            Date lastYearStartTime = DateUtils.addYears(new Date(startTime), -1);
            Date lastYearEndTime = DateUtils.addDays(lastYearStartTime, 1);

            //从user表中查询新增数
            Integer thisYearCount = this.userService.queryUserByTime(new Date(startTime), endTime);
            Integer lastYearCount = this.userService.queryUserByTime(lastYearStartTime, lastYearEndTime);

            //把今年数据封装到DataVo
            DataVo thisYearDataVo = this.getDataVo(thisYearCount, getMonth(startDate), getDay(startDate));
            DataVo lastYearDataVo = this.getDataVo(lastYearCount, getMonth(lastYearStartTime), getDay(lastYearStartTime));

            //把DataVo添加到对应集合中
            thisYearList.add(thisYearDataVo);
            lastYearList.add(lastYearDataVo);


        }

        //创建AddUsersVo对象,最后要返回给前端
        AddUsersVo addUsersVo = new AddUsersVo();
        addUsersVo.setThisYear(thisYearList);
        addUsersVo.setLastYear(lastYearList);

        return addUsersVo;
    }


    //封装DataVo
    private DataVo getDataVo(Integer Count, int month, int day) {
        DataVo thisYearDataVo = new DataVo();
        thisYearDataVo.setTitle(String.valueOf(month) + "月" + day + "号"); //本年默认月份
        thisYearDataVo.setAmount(Count);     //本年默认月新增用户数量
        return thisYearDataVo;
    }


    /**
     * 概要统计信息
     *
     * @return
     */
    public SummaryVo summary() {

        SummaryVo summaryVo = new SummaryVo();

        /**
         * 获取用户总数量
         */
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        Integer userCount = this.userInfoMapper.selectCount(queryWrapper);
        summaryVo.setCumulativeUsers(userCount);

        /**
         * 获取过去30天活跃用户
         */
        Date now = new Date();
        long nowTime = now.getTime();//当前时间

        long timePassMonth = DateUtils.addDays(now, -30).getTime();//30天前
        Integer activePassMonth = this.dashboardApi.queryActiveUser(timePassMonth, nowTime);
        summaryVo.setActivePassMonth(activePassMonth);

        /**
         * 获取过去7天活跃用户
         */
        long timePassWeek = DateUtils.addDays(now, -7).getTime();//7天前
        Integer activePassWeek = this.dashboardApi.queryActiveUser(timePassWeek, nowTime);
        summaryVo.setActivePassWeek(activePassWeek);

        /**
         * 获取今日活跃用户
         */
        String today = DateUtil.today();  //2021-10-13
        //使用糊涂工具获取今日0点0分的long值
        long todayStartTime = DateUtil.parseDateTime(today + " 00:00:00").getTime();
        Integer activeToday = this.dashboardApi.queryActiveUser(todayStartTime, nowTime);
        summaryVo.setActiveUsersToday(activeToday);


        /**
         * 获取昨日活跃用户
         */

        //设置昨天的起始时间  2021-10-12 00:00:00
        long yesterdayStartTime = DateUtils.addDays(new Date(todayStartTime), -1).getTime();

        long yesterdayEndTime = 0L;
        try {
            Date date = DateUtils.addDays(new SimpleDateFormat("yyyy-MM-dd").parse(today), -1);

            String format = new SimpleDateFormat("yyyy-MM-dd").format(date);


            //设置昨天的结束时间  2021-10-12 23:59:59
            yesterdayEndTime = DateUtil.parseDateTime(format + " 23:59:59").getTime();


            //System.out.println(DateUtil.parseDateTime(format + " 23:59:59"));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        //获取到昨天活跃数
        Integer activeUsersYesterday = this.dashboardApi.queryActiveUser(yesterdayStartTime, yesterdayEndTime);

        summaryVo.setActiveUsersYesterday(activeUsersYesterday);

        /**
         * 获取今日活跃用户涨跌率
         */

        //根据今日和昨日的活跃用户计算出获取今日活跃用户涨跌率
        //公式:(今-昨)/昨

        //先对昨日活跃用户数activeUsersYesterday进行非0判断
        if (activeUsersYesterday == 0) {
            summaryVo.setActiveUsersTodayRate(0); //如果昨日活跃用户数是0,就把今日活跃用户涨跌率设置为0
        } else {

            Integer usersTodayRate = null;
            try {
                usersTodayRate = (activeToday - activeUsersYesterday) / activeUsersYesterday;

            } catch (Exception e) {
                e.printStackTrace();
            }
            summaryVo.setActiveUsersTodayRate(usersTodayRate);
        }


        /**
         * 今日新增用户
         */
        QueryWrapper<User> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.gt("created", new Date(todayStartTime));
        queryWrapper1.lt("created", new Date());
        Integer todayNewUserCount = this.userMapper.selectCount(queryWrapper1);

        summaryVo.setNewUsersToday(todayNewUserCount);

        /**
         * 今日新增用户涨跌率
         */
        //先算出昨天的新增用户
        QueryWrapper<User> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.gt("created", new Date(yesterdayStartTime));
        queryWrapper2.lt("created", new Date(yesterdayEndTime));
        Integer yesterdayNewUserCount = this.userMapper.selectCount(queryWrapper2);


        Integer newUsersTodayRate = null;


        //对昨日新增用户数进行非0判断
        if (yesterdayNewUserCount == 0) {
            summaryVo.setNewUsersTodayRate(0); //如果昨日新增用户数是0,就把今日新增用户涨跌率设置为0
        } else {

            try {
                //计算出今日新增用户涨跌率
                newUsersTodayRate = (todayNewUserCount - yesterdayNewUserCount) / yesterdayNewUserCount;
            } catch (Exception e) {
                e.printStackTrace();
            }
            summaryVo.setNewUsersTodayRate(newUsersTodayRate);
        }


        /**
         * 今日登录次数
         */
        Integer todayLogCount = this.dashboardApi.queryLogCount(todayStartTime, new Date().getTime());
        summaryVo.setLoginTimesToday(todayLogCount);


        /**
         * 今日登录次数涨跌率
         */

        //先查询出昨日登录总次数
        Integer yesterdayLogCount = this.dashboardApi.queryLogCount(yesterdayStartTime, yesterdayEndTime);
        Integer loginTimesTodayRate = null;


        //对昨日登录总次数进行非0判断
        if (yesterdayLogCount == 0) {
            summaryVo.setLoginTimesTodayRate(0); //如果昨日登录总次数为0,就把今日登录次数涨跌率设置为0
        } else {

            try {
                //根据今日和昨日的登录总次数计算出今日登录次数涨跌率
                loginTimesTodayRate = (todayLogCount - yesterdayLogCount) / yesterdayLogCount;

            } catch (Exception e) {
                e.printStackTrace();
            }

            summaryVo.setLoginTimesTodayRate(loginTimesTodayRate);
        }

        /**
         * 昨日活跃用户涨跌率
         * 思路:(昨天活跃用户-前天活跃用户)/前天活跃用户
         */

        //先计算出前天活跃用户
        //设置前天的起始时间  2021-10-11 00:00:00
        long beforeYesterdayStartTime = DateUtils.addDays(new Date(todayStartTime), -2).getTime();

        long beforeYesterdayEndTime = 0L;
        try {
            Date date = DateUtils.addDays(new SimpleDateFormat("yyyy-MM-dd").parse(today), -2);

            String format = new SimpleDateFormat("yyyy-MM-dd").format(date);


            //设置前天的结束时间  2021-10-11 23:59:59
            beforeYesterdayEndTime = DateUtil.parseDateTime(format + " 23:59:59").getTime();

        } catch (ParseException e) {
            e.printStackTrace();
        }

        //获取到前天活跃数
        Integer activeUsersBeforeYesterday = this.dashboardApi.queryActiveUser(beforeYesterdayStartTime, beforeYesterdayEndTime);

        //用昨天活跃用户数和前天活跃用户数计算出昨日活跃用户涨跌率
        //公式:(昨天活跃用户-前天活跃用户)/前天活跃用户

        if (activeUsersBeforeYesterday == 0) {
            summaryVo.setActiveUsersYesterdayRate(0);  //如果前日活跃数为0,就把昨日活跃用户涨跌率设置为0
        } else {

            Integer activeUsersYesterdayRate = null;
            try {
                activeUsersYesterdayRate = (activeUsersYesterday - activeUsersBeforeYesterday) / activeUsersBeforeYesterday;
            } catch (Exception e) {
                e.printStackTrace();
            }
            summaryVo.setActiveUsersYesterdayRate(activeUsersYesterdayRate);
        }

        /**
         * 过去7天平均日使用时长,单位秒
         * 思路:先计算出每个用户的使用时长:(登录时间-登入时间)
         *  再将每个用户的使用时长累加
         *
         */

        //先获取到过去7天的所有UserLogin集合
        List<UserLogin> all = this.dashboardApi.findAllByTime(timePassWeek, new Date().getTime());


        long totalTime = 0L;
        for (UserLogin userLogin : all) {
            Long logTime = userLogin.getLogTime();
            Long logoutTime = userLogin.getLogoutTime();
            //当前当前用户的使用时长
            totalTime += (logoutTime - logTime);
        }
        long avgUserTime = totalTime / 7;

        //要把long值转换成秒
        summaryVo.setUseTimePassWeek(new Date(avgUserTime).getSeconds());

        return summaryVo;

    }
}
